/*----------------------------页面区域---------------------------------*/
<template>
    <el-card>
        <template #header>
            <div class="card-header">
                <span>controller控制器代码</span>
				<el-button class="button" type="text" @click="selectText">选中文本</el-button>
                <el-button class="button" type="text" @click="copyCode">一键复制</el-button>
            </div>
        </template>
		<div class="gfcodeboxcontroller">
		<pre ref="gfcode" class="gfcode">
/* {{ props.data.name }}--------自动化代码---------------------- 开始*/
// 包装对外暴露对象
var {{ props.data.name}} gu{{ props.data.name}}
type gu{{ props.data.name}} struct {}

// Creat 创建记录
func (gu gu{{ props.data.name}}) Creat(ctx context.Context,req *{{ props.data.apiFile }}.{{ props.data.name }}CreatReq)(res *{{ props.data.apiFile }}.{{ props.data.name }}CreatRes,err error){
	err = {{ props.data.serverFile }}.{{ props.data.name}}.Creat(ctx,req.Instance)
	if err != nil {
		return nil, err
	}
	res = &{{ props.data.apiFile }}.{{ props.data.name }}CreatRes{
		IsSuccess: true,
	}
	return
}
// Update 更新记录
func (gu gu{{ props.data.name}}) Update(ctx context.Context,req *{{ props.data.apiFile }}.{{ props.data.name }}UpdateReq)(res *{{ props.data.apiFile }}.{{ props.data.name }}UpdateRes,err error){
	err = {{ props.data.serverFile }}.{{ props.data.name}}.Update(ctx,req.Instance)
	if err != nil {
		return nil, err
	}
	res = &{{ props.data.apiFile }}.{{ props.data.name }}UpdateRes{
		IsSuccess: true,
	}
	return
	return
}
// React 根据id获取记录
func (gu gu{{ props.data.name}}) React(ctx context.Context,req *{{ props.data.apiFile }}.{{ props.data.name}}ReadReq)(res *{{ props.data.apiFile }}.{{ props.data.name }}ReadRes,err error){
	var instance *entity.{{ props.data.sqlname }}
	instance,err = {{ props.data.serverFile }}.{{ props.data.name}}.React(ctx,req.Id)
	if err != nil {
		return nil, err
	}
	res = &{{ props.data.apiFile }}.{{ props.data.name }}ReadRes{
		Instance: instance,
	}
	return
}
// Delete 根据id删除单条
func (gu gu{{ props.data.name}}) Delete(ctx context.Context,req *{{ props.data.apiFile }}.{{ props.data.name }}DeleteReq)(res *{{ props.data.apiFile }}.{{ props.data.name }}DeleteRes,err error){
	err = {{ props.data.serverFile }}.{{ props.data.name}}.Delete(ctx,req.Id)
	if err != nil {
		return nil, err
	}
	res = &{{ props.data.apiFile }}.{{ props.data.name }}DeleteRes{
		IsSuccess: true,
	}
	return
}
// DeleteByIds 根据id数组批量删除数据
func (gu gu{{ props.data.name}}) DeleteByIds(ctx context.Context,req *{{ props.data.apiFile }}.{{ props.data.name }}DeleteByIdsReq)(res *{{ props.data.apiFile }}.{{ props.data.name }}DeleteByIdsRes,err error){
	err = {{ props.data.serverFile }}.{{ props.data.name}}.DeleteByIds(ctx,req.Ids)
	if err != nil {
		return nil, err
	}
	res = &{{ props.data.apiFile }}.{{ props.data.name }}DeleteByIdsRes{
		IsSuccess: true,
	}
	return
}
// GetList 分页获取记录
func (gu gu{{ props.data.name}}) GetList(ctx context.Context,req *{{ props.data.apiFile }}.{{ props.data.name }}ListReq)(res *{{ props.data.apiFile }}.{{ props.data.name }}ListRes,err error){
	var list []*entity.{{ props.data.sqlname }}
	list,err = {{ props.data.serverFile }}.{{ props.data.name}}.GetList(ctx,req.Page)
	if err != nil {
		return nil, err
	}
	res = &{{ props.data.apiFile }}.{{ props.data.name }}ListRes{
		List: list,
	}
	return
}
/* {{ props.data.name }}--------自动化代码------------------ 结束*/
		</pre>			
		</div>

    </el-card>
</template>
/*----------------------------逻辑区域---------------------------------*/
<script setup>
import {ref,getCurrentInstance  } from 'vue'
const { proxy } = getCurrentInstance()
const gfcode = ref(null)
const props = defineProps({
    data: {
        type: Object
    }
})
function copyCode(){
    proxy.$copyText(gfcode.value.innerHTML).then(function (e) {
          proxy.$message.success('复制成功')
          console.log(e)
        }, function (e) {
          proxy.$message.error("复制失败")
          console.log(e)
        })
}
function selectText(){
    var range = document.createRange();
    var referenceNode =  document.getElementsByClassName("gfcodeboxcontroller").item(0); 
    console.log(referenceNode);
    range.selectNodeContents(referenceNode);
    var selection = window.getSelection();
    selection.removeAllRanges();
    selection.addRange(range) 
}
</script>
<style lang="scss" scoped>
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.text {
    font-size: 14px;
}
.item {
    margin-bottom: 18px;
}
.box-card {
    width: 480px;
}
.gfcode {
    background-color: #f3f4f6;
    padding: 20px;
}
</style>

